package com.usabb.service.impl;

import com.ifast.common.base.CoreServiceImpl;
import com.usabb.api.dto.AmenitiesDTO;
import com.usabb.dao.AmenityDao;
import com.usabb.domain.AmenityDO;
import com.usabb.enums.BizTypeEnum;
import com.usabb.service.AmenityRelationService;
import com.usabb.service.AmenityService;
import com.usabb.utils.AmenityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * <pre>
 * 配套config表
 * </pre>
 * <small> 2019-08-19 18:03:27 | Aron</small>
 */
@Service
public class AmenityServiceImpl extends CoreServiceImpl<AmenityDao, AmenityDO> implements AmenityService {

    @Autowired
    AmenityRelationService amenityRelationService;

    @Override
    public AmenitiesDTO getByBizTypeAndBizId(BizTypeEnum bizTypeEnum, Long bizId) {
        List<Long> relationAmenityIds = amenityRelationService.getAmenityIdListBy(bizTypeEnum.name(), bizId);
        if (CollectionUtils.isEmpty(relationAmenityIds)) {
            log.info("No relationAmenity info. bizType:{}, bizId:{}", bizTypeEnum, bizId);
            return new AmenitiesDTO();
        }
        List<AmenityDO> amenityDOS = this.selectBatchIds(relationAmenityIds);
        return AmenityUtils.extractTo(amenityDOS);
    }

}
